{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用langchain连接 open ai\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "os.environ['OPENAI_API_KEY'] = 'sk-fumkL2Nvub7ibL0J3d27237a09Df4e3194EcE6E317149a60'\n",
    "os.environ['OPENAI_BASE_URL'] = 'https://api.gpts.vin/v1'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.llms import openai\n",
    "# from openai import OpenAI\n",
    "from langchain import PromptTemplate, LLMChain\n",
    "from langchain_community.llms.openai import (\n",
    "    AzureOpenAI,\n",
    "    BaseOpenAI,\n",
    "    OpenAI,\n",
    "    OpenAIChat,\n",
    ")\n",
    "\n",
    "template = \"\"\"Question: {question}\n",
    "\n",
    "Answer: \"\"\"\n",
    "prompt = PromptTemplate(\n",
    "        template=template,\n",
    "    input_variables=['question']\n",
    ")\n",
    "\n",
    "# user question\n",
    "question = \"Which NFL team won the Super Bowl in the 2010 season?\"\n",
    "\n",
    "\n",
    "davinci = OpenAI(\n",
    "    model='gpt-3.5-turbo',\n",
    "    api_key='sk-fumkL2Nvub7ibL0J3d27237a09Df4e3194EcE6E317149a60',\n",
    "    base_url='https://api.gpts.vin/v1'\n",
    "    )\n",
    "\n",
    "\n",
    "llm_chain = LLMChain(\n",
    "    prompt = prompt,\n",
    "    llm = davinci\n",
    ")\n",
    "\n",
    "print(llm_chain.run(question))\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
